# Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor: damir <damir@archlinux.org>

pkgname=libcdio
pkgver=2.1.0
pkgrel=3
pkgdesc="GNU Compact Disc Input and Control Library"
url="https://www.gnu.org/software/libcdio/"
arch=(loong64 x86_64)
license=(GPL3)
depends=(ncurses gcc-libs)
makedepends=(git help2man)
options=(debug)
_commit=9c7a2779846da161279bc1501e83c849cf89a594  # tags/release-2.1.0
source=("git+https://git.savannah.gnu.org/git/libcdio.git#commit=$_commit")
sha256sums=('SKIP')
validpgpkeys=('DAA63BC2582034A02B923D521A8DE5008275EC21') # R. Bernstein

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^release-//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd $pkgname

  # Format security
  git cherry-pick -n 2adb43c60afc6e98e94d86dad9f93d3df52862b1

  # realpath test failure
  git cherry-pick -n 56335fff0f21d294cd0e478d49542a43e9495ed0

  autoreconf -fvi
}

build() {
  cd $pkgname
  CFLAGS=${CFLAGS/-Werror=format-security/}
  CXXFLAGS=${CXXFLAGS/-Werror=format-security/}
  ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
    --disable-vcd-info --disable-cddb --enable-cpp-progs --disable-static \
    --enable-maintainer-mode
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd $pkgname
  make -C test check
}

package() {
  cd $pkgname
  make DESTDIR="$pkgdir" install

  sed -e "/define CDIO_LIBCDIO_SOURCE_PATH/s|.*|/* #undef CDIO_LIBCDIO_SOURCE_PATH */|" \
      -i "$pkgdir/usr/include/cdio/cdio_config.h"
}
